How can I concatenate my code properly and make this more efficient